<?php

require("pageHandler/tableHandler.php");

function needHandling($value){
	if(substr($value, 0, 1) == "[" && substr($value, strlen($value) - 1) == "]"){
		return true;
	}else{
		return false;
	}
}

function handle($value, $entity){
	if(needHandling($value)){
		$value = substr($value, 1, strlen($value) - 2);
		$parts = explode(".", $value);
		//entity processing
		if($parts[0] && $parts[0] == 'entity'){
			$i = 1;
			while($parts[$i]){
				$arr = removeFirstPart($parts);
				if(needHandling($arr)){
					return handle($arr, $entity);
				}else{
					return getEntityParameter($entity, $parts[1]);
				}
				$i++;
			}
		}
		//filter processing
		if($parts[0] && $parts[0] == 'filter'){
		}
		//create processing
		if($parts[0] && $parts[0] == 'create'){
			return "<a href='index.php?function=create&entity=".$entity."'>New</a>";
		}
		//update processing
		if($parts[0] && $parts[0] == 'update'){
			return "<a href='index.php?function=update&entity=".$entity."'>Edit</a>";
		}
		//delete processing
		if($parts[0] && $parts[0] == 'delete'){
			return "<a href='index.php?function=delete&entity=".$entity."'>Delete</a>";
		}
		//param processing
		if($parts[0] && $parts[0] == 'params'){
			$attrListStr = "";
			$obj = getEntity($entity);
			$paramList = $obj->get_params();
			if($parts[1]){
				$attr = $parts[1];
				$attrList = array();
				for($i=0; $i<sizeof($paramList); $i++){
					if($paramList[$i]->get_attribute($attr)){
						array_push($attrList, $paramList[$i]->get_attribute($attr));
					}
				}
			}
			return $attrList;
		}
	}else{
		return $value;
	}
}

function getPage($file, $entity){
	$vals = read($file);
	
	$mode = array();
	$class = "";
	$loop_tag = "";
	
	foreach($vals as $item){ 
		$mode = handleTable($entity, $item, $mode);
	}
}


?>